package com.yanqu.road.logic.activity.foxcard.game.spell;

import com.yanqu.road.entity.activity.foxcard.FoxConsumeCard;
import com.yanqu.road.entity.activity.foxcard.config.FoxCardSpellConfig;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardGameLogic;
import com.yanqu.road.logic.activity.foxcard.game.eFoxCardType;

import java.util.Collections;
import java.util.List;

public class FoxCardSpellUseBase implements FoxCardSpellUse {
    protected FoxCardSpellConfig spellConfig;
    protected FoxConsumeCard consumeCard;
    protected List<Integer> targetIdList;

    @Override
    public FoxCardSpellUse init(FoxCardSpellConfig config, List<Integer> effectTargetIdList, FoxConsumeCard consumeCard) {
        this.spellConfig = config;
        this.consumeCard = consumeCard;
        this.targetIdList = effectTargetIdList;
        return this;
    }

    protected boolean spellUse(FoxCardGameLogic gameLogic) {
        return false;
    }

    @Override
    public boolean use(FoxCardGameLogic gameLogic) {
        boolean ret = spellUse(gameLogic);
        if (ret) {
            if (consumeCard != null) {
                gameLogic.destroyConsumeCards(Collections.singletonList(consumeCard));
            }

            if (spellConfig.getType() != 6) {
                gameLogic.getGameData().setLastUsedConsumeCardId(spellConfig.getId() * 100 + eFoxCardType.SPELL.getValue());
            }

            Integer times = gameLogic.getGameData().getConsumeCardTimesMap().getOrDefault(eFoxCardType.SPELL.getValue(), 0);
            gameLogic.getGameData().getConsumeCardTimesMap().put(eFoxCardType.SPELL.getValue(), times + 1);//累计消耗卡牌使用次数
            gameLogic.setLastUseConsumeType(eFoxCardType.SPELL.getValue());
        }
        return ret;
    }
}
